package metier.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.TableGenerator;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

@Entity
@TableGenerator(name = "SQ_PROFIL", allocationSize = 1)
public class Profil implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -155049035716292455L;

    @Id
    @Column
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SQ_PROFIL")
    private int id;
    @Column
    private String libelle;
    @ManyToMany
    @JoinTable(joinColumns = {
        @JoinColumn(name = "PROFIL_ID", referencedColumnName = "ID")},
            inverseJoinColumns = {
                @JoinColumn(name = "ROLE_ID", referencedColumnName = "CODE")})
    private List<Role> listeRole;

    public Profil() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLibelle() {
        return libelle;
    }

    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }

    public List<Role> getListeRole() {
        return listeRole;
    }

    public void setListeRole(List<Role> listeRole) {
        this.listeRole = listeRole;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(id).toHashCode();
    }

    @Override
    public boolean equals(Object object) {
        if (object == null) {
            return false;
        }
        if (object == this) {
            return true;
        }
        if (object.getClass() != getClass()) {
            return false;
        }
        Profil other = (Profil) object;
        return new EqualsBuilder().append(id, other.id).isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).append(id).toString();
    }

}
